﻿using System.Text;
using System.Windows;
using System.Windows.Input;
using Panuon.UI.Silver;
using Panuon.UI.Silver.Core;

namespace MyOS.Views.ChildView
{
    public delegate void GetFileName(string value);

    /// <summary>
    ///     RenameView.xaml 的交互逻辑
    /// </summary>
    public partial class RenameView : WindowX
    {
        public string text;


        public RenameView()
        {
            InitializeComponent();
        }

        public event GetFileName getFileName;

        private void ButtonOk_Click(object sender, RoutedEventArgs e)
        {
            text = Box.Text;
            if (text.IsNullOrEmpty())
            {
                var result = MessageBoxX.Show("请输入文件名！", "Error", Application.Current.MainWindow, MessageBoxButton.OK,
                    new MessageBoxXConfigurations
                    {
                        OKButton = "好的",
                        MinHeight = 180,
                        MinWidth = 300,
                        MessageBoxIcon = MessageBoxIcon.Error,
                        ButtonBrush = "#FF4C4C".ToColor().ToBrush()
                    });
            }
            else if (Encoding.Default.GetBytes(text).Length > 3)
            {
                var result = MessageBoxX.Show("文件名过长。(Max = 3)", "Error", Application.Current.MainWindow,
                    MessageBoxButton.OK, new MessageBoxXConfigurations
                    {
                        OKButton = "好的",
                        MinHeight = 180,
                        MinWidth = 300,
                        MessageBoxIcon = MessageBoxIcon.Error,
                        ButtonBrush = "#FF4C4C".ToColor().ToBrush()
                    });
            }
            else
            {
                getFileName(text);
                Close();
            }
        }

        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            getFileName(null);
            Close();
        }

        private void WindowX_Loaded(object sender, RoutedEventArgs e)
        {
            Keyboard.Focus(Box);
        }
    }
}